@import url('./variable.less');
@side-width: 260px;

body.md-reader {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // Automatic equation numbers for some environments.
  // Use parallel counters for HTML and MathML.
  counter-reset: katexEqnNo mmlEqnNo;
  *:not(.mermaid *) {
    box-sizing: border-box;
  }

  .md-reader {
    &__side {
      overflow: auto;
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      width: @side-width;
      line-height: 1.4;
      font-size: 14px;
      padding: 22px 0;
      border-right: 1px solid var(--color-side-border);
      margin: 0;
      list-style: none;
      color: var(--color-side);
      background: var(--color-side-bg);
      transition: transform 0.3s, box-shadow 0.5s;
      will-change: transform, box-shadow;
      z-index: 1;
      li {
        &.md-reader__side-li--active {
          a {
            font-weight: bolder;
            color: var(--color-primary);
          }
        }
        a {
          overflow: hidden;
          display: -webkit-box;
          padding: 0.3em 1.6em 0.3em 0;
          word-break: break-all;
          text-overflow: ellipsis;
          text-decoration: none;
          transition: color 0.1s;
          color: inherit;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          &:hover {
            color: var(--color-primary);
          }
        }
        &.md-reader__side {
          .head-indent (@l) {
            padding-left: 0.618em * (@l - 1) + 1.6em;
          }
          &-h1 a {
            .head-indent(1);
            font-size: 1.02em;
            font-weight: bolder;
          }
          &-h2 a {
            .head-indent(2);
            font-size: 1.01em;
            font-weight: bolder;
          }
          &-h3 a {
            .head-indent(3);
          }
          &-h4 a {
            .head-indent(4);
          }
          &-h5 a {
            .head-indent(5);
          }
          &-h6 a {
            .head-indent(6);
          }
        }
      }
    }

    &__body {
      min-height: 100vh;
      padding-left: @side-width;
      transition: padding 0.3s;
      .md-reader__markdown-content {
        padding: 30px 70px 40px;
        margin: auto;
        color: var(--color-text-primary);
        transition: max-width 0.1s;
        &.centered {
          max-width: 900px;
        }
        .theme(); // markdown theme
        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
          .md-reader__head-anchor {
            position: absolute;
            opacity: 0;
            text-decoration: none;
            padding-right: 8px;
            margin-left: -0.8em;
            border: none;
            cursor: pointer;
            color: var(--color-primary);
            transition: opacity 0.3s;
          }
          &:hover {
            .md-reader__head-anchor {
              opacity: 1;
            }
          }
        }
        // code-block copy button
        pre.md-reader__code-block {
          position: relative;
          code {
            &:empty + .md-reader__btn--copy {
              display: none;
            }
            &::before {
              transition: opacity 0.2s;
            }
          }
          &:hover {
            code::before {
              opacity: 0;
            }
            .md-reader__btn--copy {
              opacity: 1;
            }
          }
        }
      }
    }

    &__btn {
      &--side-expand {
        display: initial;
      }
    }

    &__modal {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      transition: 0.3s;
      transition-property: backdrop-filter, background;
      will-change: backdrop-filter, background;
      z-index: 1;
      cursor: zoom-out;
      &.opened {
        backdrop-filter: blur(10px);
        background: var(--color-modal-bg);
        .md-reader__zoom-image {
          opacity: 1;
        }
      }
      .md-reader__zoom-image {
        position: absolute;
        top: 0;
        left: 0;
        border: none;
        outline: none;
        margin: 0;
        opacity: var(--opacity-img);
        transition: 0.3s;
        transition-property: transform, opacity, width, height;
        will-change: transform, opacity, width, height;
        user-select: none;
        cursor: inherit;
      }
    }

    @media screen and (max-width: 960px) {
      &__side {
        transform: translateX(-100%);
        border-color: transparent;
      }
      &__body {
        padding-left: 0px;
      }
      &__btn--side-expand {
        transform: translateX(0);
      }
    }
    @media screen and (min-width: 1660px) {
      &__body {
        .md-reader__markdown-content.centered {
          max-width: 1200px;
        }
      }
    }
    @media screen and (min-width: 2048px) {
      &__body {
        .md-reader__markdown-content.centered {
          max-width: 1600px;
        }
      }
    }
    @media print {
      &__button-wrap {
        display: none;
      }
      &__body {
        .md-reader__markdown-content {
          pre.hljs-pre .hljs {
            white-space: pre-wrap;
          }
        }
      }
    }
  }

  &.side-collapsed {
    .md-reader {
      &__side {
        transform: translateX(-100%);
        border-color: transparent;
      }
      &__body {
        padding-left: 0px;
      }
      &__btn--side-expand {
        transform: translateX(0);
      }
    }
  }
  &.side-expanded {
    .md-reader {
      &__side {
        box-shadow: var(--color-side-shadow);
        transform: translateX(0);
      }
      &__btn--side-expand {
        transform: translateX(-50px);
      }
    }
  }
}

.md-reader {
  // buttons
  &__button-wrap {
    position: fixed;
    height: 0;
    top: 16px;
    left: 0;
    right: 0;
    z-index: 1;
  }

  &__btn {
    width: 32px;
    height: 32px;
    padding: 7px;
    border-radius: 10px;
    border: none;
    outline: none;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    backdrop-filter: blur(3px);
    background: var(--color-button-bg);
    color: var(--color-button);
    &:hover {
      background: var(--color-button-bg-hover);
      color: var(--color-button-hover);
    }
    &:active {
      background: var(--color-button-bg-active);
      color: var(--color-button-active);
      svg {
        transform: scale(0.95);
      }
    }
    svg {
      width: 100%;
      height: 100%;
      fill: currentColor;
      transition: 0.1s;
      transition-property: transform, color;
      transform-origin: center center;
      pointer-events: none;
      filter: drop-shadow(var(--shadow-button-text));
      * {
        pointer-events: none;
      }
    }
    &--code-toggle {
      position: absolute;
      right: 16px;
    }
    &--side-expand {
      display: none;
      position: absolute;
      left: 16px;
      transition: background 0.1s, color 0.1s, transform 0.3s;
      transform: translateX(@side-width);
    }
    &--go-top {
      position: fixed;
      right: 16px;
      bottom: 16px;
    }
    &--copy {
      opacity: 0;
      position: absolute;
      top: 6px;
      right: 10px;
      width: 30px;
      height: 30px;
      transition: opacity 0.2s, background 0.1s, color 0.1s;
      z-index: 1;
      background: var(--color-button_copy-bg);
      color: var(--color-button_copy);
      &:hover {
        background: var(--color-button_copy-bg-hover);
        color: var(--color-button_copy-hover);
      }
      &:active {
        background: var(--color-button_copy-bg-active);
        color: var(--color-button_copy-active);
      }
      svg.icon-copy {
        display: initial;
      }
      svg.icon-success {
        color: var(--color-success);
        display: none;
      }
      &.copied {
        svg.icon-copy {
          display: none;
        }
        svg.icon-success {
          display: initial;
        }
      }
    }
  }
}
